<template>
 <div>
<el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
>
  <el-form ref="form" :model="form" label-width="80px" :rules="rules">
  <el-form-item label="文章标题" prop="title">
<el-input type="text" v-model="form.title" placeholder="请输入"></el-input>
  </el-form-item>
    <el-form-item label="文章内容" prop="articleBody">
<quill-editor v-model="form.articleBody" :options="editorOption" ></quill-editor>
  </el-form-item>
    <el-form-item label="视频地址">
<el-input type="text" v-model="form.videoURL" placeholder="请输入"></el-input>
  </el-form-item>
</el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="changeAudit">确 定</el-button>
  </span>
</el-dialog>
 </div>
</template>

<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor'
import { detail } from '@/api/hmmm/articles.js'
export default {
  components: {
    quillEditor
  },
  name: 'articlesAdd',
  props: {
    id: {
      type: Number,
      default: null
    }
  },
  data () {
    return {
      dialogVisible: false,
      form: {
        id: null,
        title: '',
        articleBody: '',
        videoURL: ''
      },
      rules: {
        title: [{ required: true, message: '请选择', trigger: 'blur' }],
        articleBody: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      editorOption: {
        modules: {
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'], // 加粗，斜体，下划线，删除线
            [{ header: 1 }, { header: 2 }], // 标题，键值对的形式；1、2表示字体大小
            [{ indent: '-1' }, { indent: '+1' }], // 缩进
            ['image', 'video'] // 上传图片、上传视频
          ]
        },
        placeholder: '输入内容...'
      } // 编辑器配置项
    }
  },
  methods: {
    openDialog () {
      this.dialogVisible = true
    },
    closeDialog () {
      this.form = {
        id: null,
        title: '',
        articleBody: '',
        videoURL: ''
      }
      this.$refs.form.resetFields()
      this.dialogVisible = false
    },
    async changeAudit () {
      try {
        await this.$refs.form.validate()
        this.$emit('changeArticles', this.form)
      } catch (error) {
        console.log(error)
      }
    },
    async geteditList (id) {
      const { data } = await detail({ id })
      this.form = { ...data }
      this.openDialog()
    }
  }
}
</script>

<style scoped lang='less'>
.quill-editor /deep/ .ql-container {
    min-height: 220px;
  }

</style>
